/**
 * 添加或者修改页面
 */
var OrtherServiceInfoDlg = {
    data: {
        id: "",
        name: "",
        ms: "",
        svg: "",
        detail: "",
        pic: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;





  //实例化编辑器
    var ue = UE.getEditor('detail', {
        enableAutoSave: false,
        autoHeightEnabled: true,
        autoFloatEnabled: false,
        scaleEnabled: true,         //滚动条
        initialFrameHeight: 400     //默认的编辑区域高度
    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function (action) {
        if (action === 'uploadimage' || action === 'uploadscrawl' || action === 'uploadimage') {
            return Feng.ctxPath + '/ueditor/imgUpdate';
        } else if (action === 'uploadfile') {
            return Feng.ctxPath + '/ueditor/uploadfile';
        } else if (action === 'uploadvideo') {
            return Feng.ctxPath + '/ueditor/uploadvideo';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    };
    
  //普通图片上传
    var upload = layui.upload;
    upload.render({
        elem: '#picBtn'
        ,accept: 'images'
        ,url: Feng.ctxPath + '/system/uploadoss' //改成您自己的上传接口
        ,done: function(res){
        	Feng.success("上传成功！");
        	var url = res.data.url
        	
        	$("#picadd").attr("style","display:none;")
        	$("#picimg").attr("src",url)
        	$("#pic").val(url)
        	$("#picimg").attr("style","display:block;")
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });





    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/ortherService/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});